import logging


# 按行读取文本文件
def read_lines(filepath: str) -> []:
    lines = []
    f = None
    try:
        f = open(filepath)  # 返回一个文件对象
        lns = f.readline()
        while lns:
            lines.append(lns)
            lns = f.readline()

        return lines

    except FileNotFoundError:
        logging.error('File not found: ' + filepath)
        return None

    finally:
        if f:
            f.close()


def write_lines(filepath: str, lines: []):
    f = None
    try:
        f = open(filepath, 'w')  # 返回一个文件对象
        f.writelines(lines)
        f.flush()

    except FileNotFoundError:
        logging.error('File not found: ' + filepath)
        return None

    finally:
        if f:
            f.close()
